<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box{
      height: 240px;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- 盒子 -->
    <div ref="box" class="box">盒子</div>
    <span ref="span">span</span>
    <!-- 特殊情况，在v-for的标签上加了ref -->
    <ul>
      <!-- v-for="序号 in 次数" 序号从1开始 -->
      <li ref="li" v-for="i in 3" :key="i">{{i}}</li>
    </ul>
    <!-- 按钮 -->
    <button @click="getHeight()">获取盒子高度</button>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: "#app",
      methods: {
        getHeight () {
          // 先拿到dom容器再获取高度
          console.log(this.$refs)
          const box = this.$refs.box
          console.log(box.offsetHeight)

          // 如果给v-for的标签加了ref
          // 会获取到所有的元素 就是数组  [dom,dom,dom]
          console.log(this.$refs.li)
        }
      }
    })
  </script>
</body>

</html>